<!DOCTYPE html>
<html lang="en">
  <head>
      <meta charset="UTF-8">
      <title>模板字符串的使用`str`</title>
  </head>
  <script type="text/javascript">
    //1.模板字符串，换行会原生输出
    let str1 = `for(int i = 0; i< 10;i++){
      System.out.println("i=" + i);
    }`;
    console.log("str1=", str1);

    //2.字符串可以插入变量和表达式，变量名写在${}中，类似于EL表达式
    //  ${}中可以放入JavaScript表达式
    let name = "lmy";
    //当解析到${name}，就找最近的name遍历，进行替换
    //然后可以得到最后解析的字符串
    let str2 = `名称=${name}`;
    console.log("str2=", str2);

    let n1 = 20;
    let n2 = 30;
    let str3 = `${n1} + ${n2} = ${n1 + n2}`;
    console.log(str3);

    //3.字符串调用函数
    function sayHi(name) {
      return "hi " + name;
    }
    let str = `sayHi() 返回的结果是${sayHi('jack')}`;
  </script>
  <body>

  </body>
</html>